#coding: utf-8

sh_a='http://biz.finance.sina.com.cn/stock/market_hq.php?type=61&by=symbol&order=asc'
sh_b='http://biz.finance.sina.com.cn/stock/market_hq.php?type=62&by=symbol&order=asc'
sz_a='http://biz.finance.sina.com.cn/stock/market_hq.php?type=63&by=symbol&order=asc'
sz_b='http://biz.finance.sina.com.cn/stock/market_hq.php?type=64&by=symbol&order=asc'

import urllib
from BeautifulSoup import BeautifulSoup
import threading
import time

start=time.time()
total=0
def getpage (url):
    global total
    page=urllib.urlopen(url).read()
    soup=BeautifulSoup(page)
    for tr in soup.findAll('tr',{'align':'right'}):
        total+=1
        print '%s   %s'%(tr.td.string.encode('gbk'),tr.td.nextSibling.a.string.encode('gbk'))
threads=[]
for para in (sh_a,sz_a,sh_b,sz_b):
    threads.append(threading.Thread(target=getpage,args=[para]))
print '解析中...'.decode('utf-8').encode('gbk')
for t in threads:
    t.start()
for t in threads:
    t.join()
print time.time()-start
print total
